home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / modelers / geomview / source.lha / Geomview / include / lisp.h < prev    next >
C/C++ Source or Header  |  1993-03-30  |  7KB  |  264 lines

  1. /* Copyright (c) 1992 The Geometry Center; University of Minnesota
  2.    1300 South Second Street;  Minneapolis, MN  55454, USA;
  3.    
  4. This file is part of geomview/OOGL. geomview/OOGL is free software;
  5. you can redistribute it and/or modify it only under the terms given in
  6. the file COPYING, which you should have received along with this file.
  7. This and other related software may be obtained via anonymous ftp from
  8. geom.umn.edu; email: software@geom.umn.edu. */
  9.  
  10. /* Authors: Stuart Levy, Tamara Munzner, Mark Phillips */
  11.  
  12. #ifndef LISP_H
  13. #define LISP_H
  14.  
  15. #include <stdarg.h>
  16. #include "ooglutil.h"
  17. #include "fsa.h"
  18.  
  19. #include "streampool.h"
  20.  
  21. typedef struct LType LType;
  22. typedef struct LObject LObject;
  23.  
  24.  
  25. typedef union {
  26.   int i;
  27.   float f;
  28.   void *p;
  29. } LCell;
  30.  
  31. struct LType {
  32.  
  33.   /* name of type */
  34.   char *name;
  35.  
  36.   /* size of corresponding C type */
  37.   int size;
  38.  
  39.   /* extract cell value from obj */
  40.   int (*fromobj)(/* LObject *obj, void *x */);
  41.  
  42.   /* create a new LObject of this type */
  43.   LObject *(*toobj)(/* void *x */);
  44.  
  45.   /* free a cell of this type */
  46.   void (*free)(/* void *x */);
  47.  
  48.   /* write a cell value to a stream */
  49.   void (*write)(/* FILE *fp, void *x */);
  50.  
  51.   /* test equality of two cells of this type */
  52.   int (*match)(/* void *a, void *b */);
  53.  
  54.   /* pull a cell value from a va_list */
  55.   void (*pull)(/* va_list *a_list, void *x */);
  56.  
  57.   /* parse an object of this type */
  58.   LObject *(*parse)(/* Lake *lake */);
  59.  
  60.   /* magic number; always set to LTypeMagic */
  61.   int magic;
  62.  
  63. };
  64.  
  65. #define LTypeMagic 314159
  66.  
  67. #define LNAME(type)    (type->name)
  68. #define LSIZE(type)    (type->size)
  69. #define LFROMOBJ(type)    (*(type->fromobj))
  70. #define LTOOBJ(type)    (*(type->toobj))
  71. #define LFREE(type)    (*(type->free))
  72. #define LMATCH(type)    (*(type->match))
  73. #define LWRITE(type)    (*(type->write))
  74. #define LPULL(type)    (*(type->pull))
  75. #define LPARSE(type)    (*(type->parse))
  76.  
  77. struct LObject {
  78.   LType *type;
  79.   int ref;
  80.   LCell cell;
  81. };
  82.  
  83. typedef struct {
  84.   FILE *streamin;
  85.   FILE *streamout;
  86.   Pool *river;
  87.   int   timing_interests;    /* Are we time-stamping interest reports? */
  88.   float deltatime;        /* delta time between timestamps */
  89.   float nexttime;        /* Pool time when next timestamp'll be needed */
  90.   char *initial, *prefix, *suffix; /* printf format strings */
  91. } Lake;
  92.  
  93.  
  94. #define LakeMore(lake,c) ((c=fnextc(lake->streamin,0)) != ')' && c != EOF)
  95. #define POOL(lake)  ((lake)->river)
  96.  
  97. typedef struct LList {
  98.   LObject *     car;
  99.   struct LList *cdr;
  100. } LList;
  101.  
  102. typedef LObject *(*LObjectFunc)();
  103.  
  104. typedef struct LInterest {
  105.   Lake *lake;
  106.   LList *filter;
  107.   struct LInterest *next;
  108. } LInterest;
  109.  
  110. typedef struct {
  111.   enum { ANY,            /* match anything */
  112.      VAL,            /* match only our value */
  113.      NIL            /* match anything but report nil */
  114.      } flag;
  115.   LObject *value;
  116. } LFilter;
  117.  
  118. #define LFILTERVAL(lobject) ((LFilter *)(lobject->cell.p))
  119. extern LType LFilterp;
  120. #define LFILTER (&LFilterp)
  121.  
  122. /*
  123.  * Built-in objects: Lnil and Lt:
  124.  */
  125. extern LObject *Lnil, *Lt;
  126.  
  127. /*
  128.  * Built-in object types: string, list, and function.  Function type
  129.  *  is only used internally.  See lisp.c for the code that initializes
  130.  *  these type pointers.
  131.  */
  132. extern LType LStringp;
  133. #define LSTRING (&LStringp)
  134. #define LSTRINGVAL(obj) ((char*)((obj)->cell.p))
  135.  
  136. extern LType LIntp;
  137. #define LINT (&LIntp)
  138. #define LINTVAL(obj) ((obj)->cell.i)
  139.  
  140. extern LType LFloatp;
  141. #define LFLOAT (&LFloatp)
  142. #define LFLOATVAL(obj) ((obj)->cell.f)
  143.  
  144. extern LType LListp;
  145. #define LLIST (&LListp)
  146. #define LLISTVAL(obj) ((LList*)((obj)->cell.p))
  147.  
  148. #define LLAKEVAL(obj) ((Lake*)(obj->cell.p))
  149. extern LType LLakep;
  150. #define LLAKE (&LLakep)
  151.  
  152. extern LType LObjectp;
  153. #define LLOBJECT (&LObjectp)
  154.  
  155. /*
  156.  * Function definition stuff:
  157.  */
  158.  
  159. #define LASSIGN_GOOD 1
  160. #define LASSIGN_BAD  2
  161. #define LPARSE_GOOD  3
  162. #define LPARSE_BAD   4
  163.  
  164. #define LDECLARE(stuff) \
  165.   switch (LParseArgs stuff) { \
  166.   case LASSIGN_BAD: case LPARSE_BAD: return Lnil; \
  167.   case LPARSE_GOOD: return Lt; \
  168.   default: case LASSIGN_GOOD: break; \
  169.   }
  170.  
  171. extern LType Larray;
  172. #define LARRAY (&Larray)
  173.  
  174. extern LType Lend;
  175. #define LEND (&Lend)
  176.  
  177. extern LType Lhold;
  178. #define LHOLD (&Lhold)
  179.  
  180. extern LType Lliteral;
  181. #define LLITERAL (&Lliteral)
  182.  
  183. extern LType Loptional;
  184. #define LOPTIONAL (&Loptional)
  185.  
  186. extern LType Lrest;
  187. #define    LREST (&Lrest)
  188.  
  189. /*
  190.  * Function prototypes:
  191.  */
  192.  
  193. void     RemoveLakeInterests(Lake *lake);
  194. void          LInit();
  195. Lake *        LakeDefine(FILE *streamin, FILE *streamout, void *river);
  196. void          LakeFree(Lake *lake);
  197. LObject *     _LNew(LType *type, LCell *cell);
  198. #define       LNew(type,cell) _LNew(type,(LCell*)cell)
  199. LObject *     LRefIncr(LObject *obj);
  200. void          LRefDecr(LObject *obj);
  201. void          LWrite(FILE *fp, LObject *obj);
  202. void          LFree(LObject *obj);
  203. LObject    *     LCopy(LObject *obj);
  204. LObject *     LSexpr(Lake *lake);
  205. LObject *    LEvalSexpr(Lake *lake);
  206. LObject *     LEval(LObject *obj);
  207. LList    *     LListNew();
  208. LList    *     LListAppend(LList *list, LObject *obj);
  209. void          LListFree(LList *list);
  210. LList *          LListCopy(LList *list);
  211. LObject *     LListEntry(LList *list, int n);
  212. int          LListLength(LList *list);
  213. int          LParseArgs(char *name, Lake *lake, LList *args, ...);
  214. int          LDefun(char *name, LObjectFunc func, char *help);
  215. void        LListWrite(FILE *fp, LList *list);
  216. LInterest *    LInterestList(char *funcname);
  217. LObject *    LEvalFunc(char *name, ...);
  218. int        LArgClassValid(LType *type);
  219. void        LHelpDef(char *key, char *message);
  220. char *        LakeName(Lake *lake);
  221. char *        LSummarize(LObject *obj);
  222. LObject *    LMakeArray(LType *basetype, char *data, int count);
  223.  
  224. void LShow(LObject *obj);    /* for debugging; writes obj to stderr */
  225. void LListShow(LList *list);
  226. void LWriteFile(char *fname, LObject *obj);
  227.  
  228. #include "clisp.h"
  229.  
  230. /*
  231.   LDEFINE(name, ltype, doc) is the header used to declare a lisp
  232.   function.  It should be followed by the body of a function
  233.   (beginning with '{' and ending with '}').  LDEFINE delcares the
  234.   function's name to be "Lname" (the "name" argument with "L"
  235.   prepended to it).  It also defines a string named "Hname"
  236.   initialized to "doc".  The "ltype" argument gives the lisp object
  237.   type returned by the function (all functions defined via DEFILE
  238.   *must* return a lisp object.)  LDEFINE actually ignores this but
  239.   read the next paragraph.
  240.  
  241.   LDEFINE is intended for use in conjunction with the "lisp2c" shell
  242.   script which searches for calls to LDEFINE and builds a C language
  243.   interface to the functions so defined.  This script makes use of all
  244.   3 arguments to LDEFINE, plus the use of the LDECLARE macro in the
  245.   function body that follows, to build the files clang.c and clang.h.
  246.   It makes certain assumptions about the way LDEFINE and LDECLARE
  247.   are used.  See the comments at the top of lisp2c for details.
  248.   (I don't want to write the assumptions down here because if they
  249.   change I'll forget to update this comment!).
  250. */
  251.  
  252. #if defined(__STDC__) || defined(__ANSI_CPP__)
  253. #define LDEFINE( name, ltype, doc ) \
  254.   char H##name[] = doc ; LObject *L##name(Lake *lake, LList *args)
  255. #else
  256. #define LDEFINE( name, ltype, doc ) \
  257.   char H/**/name[] = doc ; LObject *L/**/name(Lake *lake, LList *args)
  258. #endif
  259.  
  260. #define LBEGIN lake, args
  261.  
  262. #endif /* ! LISP_H */
  263.  
  264.